package reports

import (
	"sync"

	"shqsoft.cn/pas3ui/base"
)

type ReptLock struct {
	lockme  *sync.Mutex
	lockMap map[string]*sync.Mutex
}

var reptLock *base.KeyLock = base.NewKeyLock()

// var reptLock *ReptLock

// func init() {
// 	reptLock = &ReptLock{
// 		lockme:  new(sync.Mutex),
// 		lockMap: make(map[string]*sync.Mutex),
// 	}
// }

// //GetReptLockInstance 获取报表生成锁
// func GetReptLockInstance() (rl *ReptLock) {
// 	return reptLock
// }

//Lock 报表生成加锁
func (rl *ReptLock) Lock(tmpTableName string) {
	rl.lockme.Lock()
	defer rl.lockme.Unlock()
	createlock, ok := rl.lockMap[tmpTableName]
	if !ok {
		createlock = new(sync.Mutex)
		rl.lockMap[tmpTableName] = createlock
	}
	createlock.Lock()
}

//Lock 报表生成解锁
func (rl *ReptLock) Unlock(tmpTableName string) {
	rl.lockme.Lock()
	defer rl.lockme.Unlock()
	createlock, ok := rl.lockMap[tmpTableName]
	if !ok {
		return
	}
	createlock.Unlock()
}
